<template>
    <div
      @mouseenter="handleMouseEnter"
      @mouseleave="handleMouseLeave"
      class="b-collapse-item">
      <div
        class="b-collapse-item__header"
        @click="isActive = !isActive"
        role="button"
        :class="{
          'is-active': isActive
        }"
      >
        <i
          class="b-collapse-item__arrow el-icon-caret-right"
          :class="{'is-active': isActive}">
        </i>
        <div @click.stop>
          <el-input
            v-if="showInput"
            style="width: 180px;"
            size="small"
            ref="nameInput"
            @blur="handleCloseNameInput"
            :maxlength="20"
            v-model="groupName"
          />
          <span v-else @dblclick.stop="handleShowChangeName" class="b-collapse-item__title">
            {{title}}
            <i @click.stop="handleShowChangeName" v-show="isHover" class="el-icon-edit"></i>
          </span>
          <el-dropdown
            placement="bottom"
            class="group-detail"
            v-show="isHover"
          >
            <i class="el-icon-more"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-question">换负责人</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete-solid">解散团队</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
      <el-collapse-transition>
        <div
          class="b-collapse-item__wrap"
          v-show="isActive"
        >
          <div class="b-collapse-item__content">
            <slot></slot>
          </div>
        </div>
      </el-collapse-transition>
    </div>
</template>

<script>
export default {
  name: 'collapse-item',
  props: {
    title: ''
  },
  data () {
    return {
      isActive: false,
      isHover: false,
      showInput: false,
      groupName: ''
    }
  },
  methods: {
    handleMouseEnter () {
      this.isHover = true
    },
    handleMouseLeave () {
      this.isHover = false
    },
    handleShowChangeName () {
      this.showInput = true
      this.groupName = this.title
      this.$nextTick(() => {
        this.$refs.nameInput.focus()
      })
    },
    handleCloseNameInput (e) {
      this.showInput = false
      this.$emit('handleChangeName', this.groupName)
    }
  }
}
</script>

<style scoped>
.b-collapse-item:hover {
  box-shadow: 0 0 1px 1px #FF8E3D;
  transition: box-shadow 0.1s ease-in-out;
}
.b-collapse-item:last-child {
  margin-bottom: -1px;
}
.b-collapse-item__header {
  display: flex;
  align-items: center;
  height: 54px;
  line-height: 54px;
  background-color: #FFF;
  color: #303133;
  cursor: pointer;
  border-bottom: 1px solid #EBEEF5;
  font-size: 13px;
  font-weight: 500;
  transition: border-bottom-color .3s;
  outline: 0;
  position: relative;
}
.b-collapse-item__title {
  font-size: 16px;
  color: #444444;
}
.b-collapse-item__arrow {
  font-size: 16px;
  margin: 0 4px 0 12px;
  transition: transform .3s;
  font-weight: 300;
  color: #BFBFBF;
}
.b-collapse-item__arrow.is-active {
  transform: rotate(90deg);
}
.b-collapse-item__wrap {
  will-change: height;
  background-color: #FFF;
  overflow: hidden;
  box-sizing: border-box;
  border-bottom: 1px solid #EBEEF5;
}
.b-collapse-item__content {
  padding: 12px 16px 16px 16px;
  font-size: 13px;
  color: #303133;
  line-height: 1.769230769230769;
}
.group-detail {
  position: absolute;
  right:10px;
  top: 18px;
  height: 10px;
  line-height: 10px;
  color:#4A4A4A;
}
.group-detail:hover {
  color:#FBAB71;
}
</style>
